package com.c.ctgproject.adapter.storage

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.c.ctgproject.R
import com.c.ctgproject.base.BaseEmptyRecyclerViewAdapter
import com.c.ctgproject.entity.storage.StorageListEntity
import com.c.ctgproject.utils.handlerNull

class StorageListAdapter(private val context: Context, private val list: ArrayList<StorageListEntity.DataBean.ListBean>, private val listener: StorageCallback) : BaseEmptyRecyclerViewAdapter<StorageListEntity.DataBean.ListBean>(context, list) {
    override fun createViewHolder(parent: ViewGroup): RecyclerView.ViewHolder {
        val view = LayoutInflater.from(context)
            .inflate(R.layout.item_storage_list, parent, false)
        return MyViewHolder(view)
    }

    override fun handlerData(holder: RecyclerView.ViewHolder, position: Int) {
        if (holder is MyViewHolder) {
            val data = list[position]
            holder.mStorageNameTV.text = data.name.handlerNull()
            holder.mStorageLL.setOnClickListener {
                listener.onItemClick(data.id)
            }
        }
    }

    inner class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
        val mStorageNameTV: TextView = view.findViewById(R.id.mStorageNameTV)
        val mStorageLL: LinearLayout = view.findViewById(R.id.mStorageLL)
    }

    interface StorageCallback {
        fun onItemClick(id: Int)
    }
}